import time
from pathlib import Path
from rich.progress import Progress, SpinnerColumn, BarColumn, TextColumn
import numpy as np
import pandas as pd

from utils.plot_style import print_start, print_end, set_chinese_font, set_plot_style, force_chinese_font
from src.plot import prepare_border_counties_population_data
from src.gif_generator import generate_density_gif
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib.ticker import FuncFormatter
import matplotlib.font_manager as fm


def run_tests():
    """在这里放置你的快速试验代码或单元级小片段。"""
    from rich.console import Console
    console = Console()
    console.rule("try.py: 运行示例测试")
    try:
        from src.core_utils import load_data
        try:
            df = load_data()
            console.log(f"load_data 成功，rows={len(df)} cols={len(df.columns)}")
            console.log("注意：回归与示例已被移除，请参见 examples/ 目录中的示例脚本。")
        except FileNotFoundError as e:
            console.log(f"load_data 未找到文件：{e}")
        except Exception as e:
            console.log(f"load_data 出错：{e}")
    except Exception:
        console.log("src.core_utils.load_data 不可用：跳过数据加载测试")
    # 演示 rich 进度条
    with Progress(
        SpinnerColumn(style="red"),
        TextColumn("[bold]测试进度"),
        BarColumn(bar_width=None, complete_style="red"),
        import runpy
        import sys


        def main():
            # 将执行委托给 try_plot.py（保留原始入口逻辑在 try_plot.py 中）
            runpy.run_path('try_plot.py', run_name='__main__')


        if __name__ == '__main__':
            try:
                main()
            except SystemExit as e:
                # 将子进程退出码传递出去
                code = e.code if isinstance(e.code, int) else 0
                import runpy
                import sys


                def main():
                    # 将执行委托给 try_plot.py（保留原始入口逻辑在 try_plot.py 中）
                    runpy.run_path('try_plot.py', run_name='__main__')


                if __name__ == '__main__':
                    try:
                        main()
                    except SystemExit as e:
                        # 将子进程退出码传递出去
                        code = e.code if isinstance(e.code, int) else 0
                        sys.exit(code)
